// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    catelist: ["男装", "女装", "零食", "家电", "床上用品", "家具"],
    bannerlist: [{
      url: "../../images/banner1.jpg"
    }, {
      url: "../../images/banner2.jpg"
    }, {
      url: "../../images/banner3.jpg"
    }
  ],
  latitude:"",
  longittude:"",
    danmulist: [{
      text: "网院",
      color: "#ff0000",
      time: 10
    }, {
      text: "电大",
      color: "#E64E69",
      time: 30
    }]
  },
  onLoad() {},
  saveUserInfo: function () {
    //同步缓存
    var data = {
      "name": "莫水珠",
      "student_id": "201965110462"
    }
    //异步缓存
    wx.setStorageSync('userinfo', data)
    wx.setStorage({
      key: "studentinfo",
      data: {
        "sex": "女",
        "age": 19
      }
    })
  },
  getUserInfo: function () {
    //同步获取缓存数据
    var studentinfo = wx.getStorageSync('studentinfo');
    console.log(studentinfo);
    //异步获取
    wx.getStorage({
      key: 'userinfo',
      success(res){
        console.log(res);
      }
    })
    wx.getStorageInfo({
      success: (option) => {
        console.log(option)
      },
    })
  },
  removeUserInfo: function () {
    //异步移除
    wx.removeStorage({
      key: 'userinfo',
    })
    wx.removeStorageSync('studentinfo')
  },
  getLocal:function(){
    var then = this;
    wx.getLocation({
      type:"gcj02",
      success(res){
        then.setData({
          latitude:res.latitude,
          longittude:res.longitude
        })
      }
    })
  },
  openMap:function(){
    var then = this;
    wx.openLocation({
      latitude: then.data.latitude,
      longitude: then.data.longittude,
      name:"湖南开发大学终教楼1104",
      address:"湖南省长沙市天心区清源路168号1104"
    })
  },
  selectLocal:function(){
    var then = this;
    wx.chooseLocation({
      latitude: then.data.latitude,
      longitude:then.data.longittude
    })
  },
  call:function(){
    wx.makePhoneCall({
      phoneNumber: '16673192730',
    })
  },
  scanCode:function(){
    wx.scanCode({
      onlyFromCamera: true,
      success(res){
        console.log(res)
      }
    })
  },
  selectImage:function(){
    wx.chooseImage({
      count: 1,
      sourceType:['camera'],//只能通过相机进行拍照
      success(res){
        console.log(res);
        wx.previewImage({
          urls: [res.tempFilePaths[0]],
        })
        wx.getImageInfo({
          src: '../../images/banner1.jpg',
          success(res){
            console.log(res)
          }
        })
      }
    })
  },
  saveImage:function(){
    wx.saveImageToPhotosAlbum({
      filePath: 'http://tmp/qg1Y9ZtjZMNp8a04bfe4e04b1c74e8d7a6679a0ca410.jpg',
    })
  },
  checkboxChange: function (e) {
    var then = this;
    var likestr = "";
    for (let index = 0; index < e.detail.value.length; index++) {
      likestr = likestr + e.detail.value[index];
    }
    then.setData({
      likes: likestr //数据的动态修改
    })
    console.log(e)
    console.log(e.detail.value[0])
  },
})